<template>
  <div class="app-container">
    <el-input
      placeholder="输入关键字进行过滤"
      v-model="filterText">
    </el-input>

    <el-tree
      class="filter-tree"
      :data="list"
      :props="defaultProps"
      default-expand-all
      :filter-node-method="filterNode"
      ref="tree">
    </el-tree>
  </div>
</template>

<script>
  import category from '@/api/video/category'
  export default {
    name: 'list',
    watch: {
      filterText(val) {
        this.$refs.tree.filter(val);
      }
    },

    methods: {
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      }
    },
    created() {
        category.getTreeModel().then(response=>{
          this.list=response.data.list
          }
        )
    },
    data() {
      return {
        filterText: '',
        list: [],
        defaultProps: {
          children: 'children',
          label: 'title'
        }
      };
    }
  }
</script>

<style scoped>

</style>
